package com.multireactor;

import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

public class AcceptorHandler implements Runnable{

    /**
     *  监听服务
     */

   private ServerSocketChannel server;

    /**
     * 工作轮询
     */
   private Selector workSel;

   private Selector reqSel;

    public AcceptorHandler(ServerSocketChannel server, Selector workSel, Selector reqSel) {
        this.server = server;
        this.workSel = workSel;
        this.reqSel=reqSel;
    }

    @Override
    public void run() {
        try {
            SocketChannel socketChannel = server.accept();
            if(socketChannel != null){
                System.out.println("acceptor:"+socketChannel.getRemoteAddress());
                socketChannel.configureBlocking(false);
                new MultiEchoEchoHandler(workSel,socketChannel);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
